home *** CD-ROM | disk | FTP | other *** search
- #ifndef __TYPES__
- #include <Types.h>
- #endif
-
- #ifndef __DIALOGS__
- #include <Dialogs.h>
- #endif
-
- #ifndef __OCE__
- #include <OCE.h>
- #endif
-
- #ifndef __OCEAUTHDIR__
- #include <OCEAuthDir.h>
- #endif
-
- #ifndef __OCESTANDARDDIRECTORY__
- #include <OCEStandardDirectory.h>
- #endif
-
- #include "utils.h"
- #include "AddressOMini.h"
-
-
- // constants
- #define kFindLayoutRsrcID 128
- #define kGetDirectoriesDialog 132
- #define kBrowseRadio 3
- #define kFindRadio 4
- #define kPanelItem 5
- #define kActive 0
- #define kDimmed 255
- #define kInFront (WindowPtr)-1L
- #define kFindText "\pFind"
- #define kStopText "\pStop"
- #define kSelectText "\pSelect"
- #define kOpenText "\pOpen"
-
- enum {
- kBrowsePanel,kFindPanel
- };
-
-
- // file globals
-
- static short gPanelKind = kBrowsePanel;
-
-
- // prototypes
-
- pascal void PanelUserItem(DialogPtr theDlg,short item);
- pascal Boolean PanelFilterEvent(DialogPtr theDlg,EventRecord *ev,short *itemHit);
- void RecalcFindButton(DialogPtr theDlg,SDPFindPanelHandle thePanel);
- void RecalcBrowseButton(DialogPtr theDlg,SDPPanelHandle thePanel);
-
-
- #if 0
- // *****************************************************************
- // * CheckPanelSize
- // *
- // * make sure the Directory Broswer "fits" into the space alloted to it
- // *****************************************************************
- void CheckPanelSize(DialogPtr dlg,Rect *panelRect,short panelItem)
- {
- Handle iHndl;
- short iType;
- FontInfo fInfo;
- short minWidth,minHeight,fontHeight;
-
-
- GetDItem(dlg,panelItem,&iType,&iHndl,panelRect);
- // ####
- GetFontInfo(&fInfo);
- minWidth = 5*fInfo.widMax + 42;
- fontHeight = fInfo.ascent + fInfo.descent + fInfo.leading;
- minHeight = fontHeight + 18;
- // #####
- minHeight = (64 > 3*fontHeight) ? (minHeight + 64) : (minHeight + 3*fontHeight);
- if ((panelRect->bottom - panelRect->top) < minHeight)
- {
- panelRect->bottom = panelRect->top + minHeight;
- SetDItem(dlg,panelItem,iType,iHndl,panelRect);
- }
- if ((panelRect->right - panelRect->left) < minWidth)
- {
- panelRect->right = panelRect->left + minWidth;
- SetDItem(dlg,panelItem,iType,iHndl,panelRect);
- }
-
- }
- #endif
-
- Boolean AddressOMini(PackedDSSpecPtr *dsSpec,
- const RStringPtr *typesList,
- unsigned long typeCount,
- AuthIdentity identity,
- DirEnumChoices enumFlags,
- ConstStr255Param promptString,
- DirMatchWith matchTypeHow)
- {
- static Boolean gHasBeenCalled = false; // save our rli location for the next time
- static PackedRLI gInitialRLI; // we call this function
- static short gDSRefNum;
-
- SDPPanelHandle browsePanel;
- SDPFindPanelHandle findPanel;
- SDPSelectionState bSelectionState;
- SDPPanelState bPanelState;
- SDPFindPanelState fPanelState;
- OSErr err;
- DialogPtr theDlg;
- short iType;
- Handle iHndl;
- Rect iRect;
- Point upLeft;
- short item;
- Boolean selectedRecord;
- unsigned short dsSpecSize;
-
- // set up prompt
-
- if (promptString)
- ParamText(promptString,nil,nil,nil);
- else
- ParamText("\pSelect a Record:",nil,nil,nil);
-
- // get the dialog
- theDlg = GetNewDialog(kGetDirectoriesDialog,nil,kInFront);
-
- SetPort(theDlg);
-
- // make panels
-
- GetDItem(theDlg,kPanelItem,&iType,&iHndl,&iRect);
- SetDItem(theDlg,kPanelItem,iType,(Handle)PanelUserItem,&iRect);
-
-
- err = SDPNewPanel(&browsePanel,(WindowPtr)theDlg,&iRect,(gPanelKind==kBrowsePanel),
- (gPanelKind==kBrowsePanel),((gHasBeenCalled) ? & gInitialRLI : nil),
- typesList,typeCount,identity,
- enumFlags,matchTypeHow,0);
- if (err!=noErr) {
- DisposeDialog(theDlg);
- return false;
- }
-
- upLeft.h = iRect.left;
- upLeft.v = iRect.top;
- err = SDPNewFindPanel(&findPanel,(WindowPtr)theDlg,upLeft,kFindLayoutRsrcID,
- (gPanelKind==kFindPanel),(gPanelKind==kFindPanel),typesList,
- typeCount,matchTypeHow,identity,1,kSDPFindPanelTextHasFocus,0);
- if (err!=noErr) {
- SDPDisposePanel(browsePanel);
- DisposeDialog(theDlg);
- return false;
- }
-
- // set up radio buttons
-
- if (gPanelKind==kBrowsePanel) {
- SetWRefCon((WindowPtr)theDlg,(long)browsePanel);
- GetDItem(theDlg,kBrowseRadio,&iType,&iHndl,&iRect);
- RecalcBrowseButton(theDlg,browsePanel);
- }
- else {
- SetWRefCon((WindowPtr)theDlg,(long)findPanel);
- GetDItem(theDlg,kFindRadio,&iType,&iHndl,&iRect);
- RecalcFindButton(theDlg,findPanel);
- }
- SetCtlValue((ControlHandle)iHndl,1);
-
- selectedRecord = false;
- do {
- ModalDialog(PanelFilterEvent,&item);
- switch (item) {
-
- case kBrowseRadio:
- if (gPanelKind!=kBrowsePanel) {
-
- // stop any finds going on
-
- if ((**findPanel).nowFinding)
- SDPStopFind(findPanel);
-
- // reset buttons
-
- GetDItem(theDlg,kBrowseRadio,&iType,&iHndl,&iRect);
- SetCtlValue((ControlHandle)iHndl,1);
- GetDItem(theDlg,kFindRadio,&iType,&iHndl,&iRect);
- SetCtlValue((ControlHandle)iHndl,0);
-
- // switch the panels
-
- SDPEnableFindPanel(findPanel,false);
- SDPHideFindPanel(findPanel);
- SetWRefCon((WindowPtr)theDlg,(long)browsePanel);
- gPanelKind = kBrowsePanel;
- SDPShowPanel(browsePanel);
- SDPEnablePanel(browsePanel,true);
-
- // udpate ok button
-
- RecalcBrowseButton(theDlg,browsePanel);
-
- }
- break;
-
- case kFindRadio:
- if (gPanelKind!=kFindPanel) {
-
- // reset buttons
-
- GetDItem(theDlg,kFindRadio,&iType,&iHndl,&iRect);
- SetCtlValue((ControlHandle)iHndl,1);
- GetDItem(theDlg,kBrowseRadio,&iType,&iHndl,&iRect);
- SetCtlValue((ControlHandle)iHndl,0);
-
- // switch the panels
-
- SDPEnablePanel(browsePanel,false);
- SDPHidePanel(browsePanel);
- SetWRefCon((WindowPtr)theDlg,(long)findPanel);
- gPanelKind = kFindPanel;
- SDPShowFindPanel(findPanel);
- SDPEnableFindPanel(findPanel,true);
-
- // update ok button
-
- RecalcFindButton(theDlg,findPanel);
- }
- break;
-
- case ok:
- if (gPanelKind==kBrowsePanel) {
-
- // browse panel ok hit
-
- SDPGetPanelSelectionState(browsePanel,&bSelectionState);
- if (bSelectionState==kSDPRecordSelected || bSelectionState==kSDPRecordAliasSelected)
- selectedRecord = true;
- else
- SDPOpenSelectedItem(browsePanel,&bPanelState);
- }
- else {
-
- // find panel ok hit
-
- SDPGetFindPanelState(findPanel,&fPanelState);
- if ((**findPanel).nowFinding) { // stop the find
- SDPStopFind(findPanel);
- GetDItem(theDlg,ok,&iType,&iHndl,&iRect);
- if (fPanelState&kSDPItemIsSelectedMask)
- SetCTitle((ControlHandle)iHndl,kSelectText);
- else
- SetCTitle((ControlHandle)iHndl,kFindText);
- }
- else if (fPanelState&kSDPItemIsSelectedMask) // select the item and exit
- selectedRecord = true;
- else if (fPanelState&kSDPFindTextExistsMask) { // start a find
- SDPStartFind(findPanel);
- }
-
- }
- break;
- }
- }
- while (!selectedRecord && item!=cancel);
-
- // get selected record, if we have one
-
- if (selectedRecord) {
- if (gPanelKind==kBrowsePanel)
- err = SDPGetPanelSelectionSize(browsePanel,&dsSpecSize);
- else
- err = SDPGetFindPanelSelectionSize(findPanel,&dsSpecSize);
- if (err==noErr) {
- *dsSpec = (PackedDSSpecPtr)NewPtr(dsSpecSize);
- if (MemError()==noErr) {
- if (gPanelKind==kBrowsePanel)
- err = SDPGetPanelSelection(browsePanel,*dsSpec);
- else
- err = SDPGetFindPanelSelection(findPanel,*dsSpec);
- }
- else err = MemError();
- }
- }
-
- // get info out for next call
-
- gHasBeenCalled = true;
- SDPGetPath(browsePanel,&gInitialRLI,&gDSRefNum);
-
- // release stuff from memory
-
- SDPDisposePanel(browsePanel);
- SDPDisposeFindPanel(findPanel);
- DisposeDialog(theDlg);
-
- return selectedRecord;
- }
-
-
- pascal void PanelUserItem(DialogPtr theDlg,short item)
- {
- #pragma unused (item)
- long thePanel;
-
- thePanel = GetWRefCon((WindowPtr)theDlg);
-
- if (gPanelKind==kBrowsePanel)
- SDPUpdatePanel((SDPPanelHandle)thePanel,nil);
- else
- SDPUpdateFindPanel((SDPFindPanelHandle)thePanel,nil);
- }
-
-
- pascal Boolean PanelFilterEvent(DialogPtr theDlg,EventRecord *ev,short *itemHit)
- {
- char theChar;
- long thePanel;
- SDPPanelState bPanelState;
- SDPFindPanelState fPanelState;
- SDPFindPanelResult fPanelResult;
- short iType;
- ControlHandle iHndl;
- Rect iRect;
- Str255 cTitle;
- OSErr err;
-
- // check for user cancel
-
- if (ev->what==keyDown) {
- theChar = ev->message & charCodeMask;
- if ((theChar==0x1b) || (theChar=='.' && ev->modifiers&cmdKey)) {
- *itemHit = cancel;
- FlashControl(theDlg,cancel);
- return true;
- }
- }
-
- if (ev->what != updateEvt) {
-
- thePanel = GetWRefCon((WindowPtr)theDlg);
-
- if (gPanelKind==kBrowsePanel) {
-
- // browse panels
-
- RecalcBrowseButton(theDlg,(SDPPanelHandle)thePanel);
-
- SDPPanelEvent((SDPPanelHandle)thePanel,ev,&bPanelState);
- if (bPanelState==kSDPSelectedAnItem) {
- *itemHit = ok;
- return true;
- }
- }
- else {
-
- // find panels
-
- GetDItem(theDlg,ok,&iType,(Handle *)&iHndl,&iRect);
- GetCTitle(iHndl,cTitle);
-
- SDPFindPanelEvent((SDPFindPanelHandle)thePanel,ev,&fPanelResult);
- switch (fPanelResult) {
- case kSDPSelectedAFindItem:
- FlashControl(theDlg,ok);
- *itemHit = ok;
- return true;
- break;
- case kSDPFindSelectionChanged:
- case kSDPTextStateChanged:
- case kSDPFocusChanged:
- case kSDPSelectionAndFocusChanged:
- case kSDPSelectionAndMenuChanged:
- GetCTitle(iHndl,cTitle);
- if (EqualString(cTitle,kStopText,true,true))
- FlashControl(theDlg,ok);
- RecalcFindButton(theDlg,(SDPFindPanelHandle)thePanel);
- break;
- case kSDPProcessedFind:
- if ((**(SDPFindPanelHandle)thePanel).nowFinding) {
- GetCTitle(iHndl,cTitle);
- if (!EqualString(cTitle,kStopText,true,true)) {
- FlashControl(theDlg,ok);
- SetCTitle((ControlHandle)iHndl,kStopText);
- }
- }
- break;
- case kSDPFindCompleted:
- err = SDPGetFindPanelState((SDPFindPanelHandle)thePanel,&fPanelState);
- if ((err==noErr) && (fPanelState&kSDPItemIsSelectedMask))
- SetCTitle((ControlHandle)iHndl,kSelectText);
- else
- SetCTitle((ControlHandle)iHndl,kFindText);
- break;
- }
- }
- }
- else
- MyDrawDefaultButtonOutline(theDlg,ok);
-
- return false;
- }
-
-
-
- void RecalcBrowseButton(DialogPtr theDlg,SDPPanelHandle thePanel)
- {
- SDPPanelState panelState;
- short iType;
- ControlHandle iHndl;
- Rect iRect;
- Str255 cTitle;
-
- SDPGetPanelSelectionState(thePanel,&panelState);
- GetDItem(theDlg,ok,&iType,(Handle *)&iHndl,&iRect);
- GetCTitle(iHndl,cTitle);
-
- switch (panelState) {
- case kSDPNothingSelected:
- case kSDPLockedContainerSelected:
- if ((**iHndl).contrlHilite!=kDimmed) {
- HiliteControl(iHndl,kDimmed);
- MyDrawDefaultButtonOutline(theDlg,ok);
- }
- if (!EqualString(cTitle,kOpenText,true,true))
- SetCTitle(iHndl,kOpenText);
- break;
- case kSDPContainerSelected:
- case kSDPContainerAliasSelected:
- if ((**iHndl).contrlHilite!=kActive) {
- HiliteControl(iHndl,kActive);
- MyDrawDefaultButtonOutline(theDlg,ok);
- }
- if (!EqualString(cTitle,kOpenText,true,true))
- SetCTitle(iHndl,kOpenText);
- break;
- case kSDPRecordSelected:
- case kSDPRecordAliasSelected:
- if ((**iHndl).contrlHilite!=kActive) {
- HiliteControl(iHndl,kActive);
- MyDrawDefaultButtonOutline(theDlg,ok);
- }
- if (!EqualString(cTitle,kSelectText,true,true))
- SetCTitle(iHndl,kSelectText);
- break;
- }
- }
-
-
- void RecalcFindButton(DialogPtr theDlg,SDPFindPanelHandle thePanel)
- {
- Str255 cTitle;
- short iType;
- ControlHandle iHndl;
- Rect iRect;
- SDPFindPanelState fPanelState;
- OSErr err;
-
- GetDItem(theDlg,ok,&iType,(Handle *)&iHndl,&iRect);
- err = SDPGetFindPanelState(thePanel,&fPanelState);
- if (err==noErr) {
- switch (fPanelState) {
- case kSDPItemIsSelectedMask:
- case (kSDPItemIsSelectedMask|kSDPFindTextExistsMask):
- if ((**iHndl).contrlHilite!=kActive) {
- HiliteControl(iHndl,kActive);
- MyDrawDefaultButtonOutline(theDlg,ok);
- }
- if (!EqualString(cTitle,kSelectText,true,true))
- SetCTitle(iHndl,kSelectText);
- break;
- case kSDPFindTextExistsMask:
- if ((**iHndl).contrlHilite!=kActive) {
- HiliteControl(iHndl,kActive);
- MyDrawDefaultButtonOutline(theDlg,ok);
- }
- if (!EqualString(cTitle,kFindText,true,true))
- SetCTitle(iHndl,kFindText);
- break;
- default:
- if ((**iHndl).contrlHilite!=kDimmed) {
- HiliteControl(iHndl,kDimmed);
- MyDrawDefaultButtonOutline(theDlg,ok);
- }
- if (!EqualString(cTitle,kFindText,true,true))
- SetCTitle(iHndl,kFindText);
- break;
- }
- }
- }